<?php

declare(strict_types=1);

namespace App\Model;


/**
 * @property int $id
 * @property string $name 礼物名
 * @property string $en_name 英文名称
 * @property string $hk_name 繁体中文名称
 * @property int $price 礼物价格（金币）
 * @property int $price2
 * @property string $img 礼物图标
 * @property int $status 0: 上架  1:下架
 * @property int $ctime 添加时间
 * @property int $orders 排序
 * @property string $effect_url 礼物动效
 */
class Gift extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'tb_gift';

    /**
     * The attributes that are mass assignable.
     */
    // protected array $fillable = [];
    protected array $guarded = [];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'price' => 'integer', 'price2' => 'integer', 'status' => 'integer', 'ctime' => 'integer', 'orders' => 'integer'];


    /**
     * Note - 根据call_id统计用户送礼消费金币
     * DateTime 2024/8/2 12:03
     * User Admin
     * @param $uid
     * @param $call_id
     * @return int|mixed|string
     */
    public function getGiftCost($uid, $call_id)
    {
        // $sql = "select sum(cost) costs from {$this->tableS} where send_uid = ? and call_id = ?";
        // $pd = $this->createCommand($sql);
        // $pd->execute(array($uid, $call_id));
        // $rs = $pd->fetch(PDO::FETCH_ASSOC);
        // return (int)$rs['costs'];
        return SendGiftItem::query()->where('send_uid', $uid)->where('call_id', $call_id)->sum('cost');
    }


    /**
     * Note - 根据call_id统计主播获得金币
     * DateTime 2024/8/2 12:04
     * User Admin
     * @param $uid
     * @param $call_id
     * @return float
     */
    public function getGiftProfit($uid, $call_id)
    {
        // $sql = "select sum(profit) profits from {$this->tableS} where get_uid = ? and call_id = ?";
        // $pd = $this->createCommand($sql);
        // $pd->execute(array($uid, $call_id));
        // $rs = $pd->fetch(PDO::FETCH_ASSOC);
        // return (float)$rs['profits'];
        return SendGiftItem::query()->where('get_uid', $uid)->where('call_id', $call_id)->sum('profit');
    }


}
